﻿CREATE PROCEDURE [dbo].[yaf_accessmask_save](
                @AccessMaskID    INT  = NULL,
                @BoardID         INT,
                @Name            NVARCHAR(50),
                @ReadAccess      BIT,
                @PostAccess      BIT,
                @ReplyAccess     BIT,
                @PriorityAccess  BIT,
                @PollAccess      BIT,
                @VoteAccess      BIT,
                @ModeratorAccess BIT,
                @EditAccess      BIT,
                @DeleteAccess    BIT,
                @UploadAccess    BIT)
AS
    BEGIN
        DECLARE  @Flags INT
        SET @Flags = 0
        IF @ReadAccess <> 0
        SET @Flags = @Flags | 1
        IF @PostAccess <> 0
        SET @Flags = @Flags | 2
        IF @ReplyAccess <> 0
        SET @Flags = @Flags | 4
        IF @PriorityAccess <> 0
        SET @Flags = @Flags | 8
        IF @PollAccess <> 0
        SET @Flags = @Flags | 16
        IF @VoteAccess <> 0
        SET @Flags = @Flags | 32
        IF @ModeratorAccess <> 0
        SET @Flags = @Flags | 64
        IF @EditAccess <> 0
        SET @Flags = @Flags | 128
        IF @DeleteAccess <> 0
        SET @Flags = @Flags | 256
        IF @UploadAccess <> 0
        SET @Flags = @Flags | 512
        IF @AccessMaskID IS NULL
        INSERT INTO yaf_AccessMask
                   (Name,
                    BoardID,
                    Flags)
        VALUES     (@Name,
                    @BoardID,
                    @Flags)
        ELSE
        UPDATE yaf_AccessMask
        SET    Name = @Name,
               Flags = @Flags
        WHERE  AccessMaskID = @AccessMaskID
    END


